package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.EmployeeContract;
import com.amsp.oa.oademo.service.EmployeeContractService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "员工合同管理")
@RestController
@RequestMapping("/api/employee-contract")
public class EmployeeContractController {

    @Autowired
    private EmployeeContractService employeeContractService;

    @ApiOperation("分页查询员工合同")
    @GetMapping("/getPage")
    public IPage<EmployeeContract> getPage(@RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size, EmployeeContract query) {
        Page<EmployeeContract> page = new Page<>(current, size);
        return employeeContractService.getEmployeeContractPage(page, query);
    }

    @ApiOperation("获取员工合同详情")
    @GetMapping("/getInfo/{id}")
    public EmployeeContract getInfo(@PathVariable Long id) {
        return employeeContractService.getById(id);
    }

    @ApiOperation("新增或更新员工合同")
    @PostMapping("/saveOrUpdate")
    public boolean saveOrUpdate(@RequestBody EmployeeContract employeeContract) {
        return employeeContractService.saveOrUpdate(employeeContract);
    }

    @ApiOperation("批量保存或更新员工合同")
    @PostMapping("/batchSaveOrUpdate")
    public boolean batchSaveOrUpdate(@RequestBody List<EmployeeContract> employeeContracts) {
        return employeeContractService.saveOrUpdateBatch(employeeContracts);
    }

    @ApiOperation("删除员工合同")
    @DeleteMapping("/remove/{id}")
    public boolean remove(@PathVariable Long id) {
        return employeeContractService.removeById(id);
    }

    @ApiOperation("批量删除员工合同")
    @PostMapping("/batchRemove")
    public boolean batchRemove(@RequestBody List<Long> ids) {
        return employeeContractService.removeByIds(ids);
    }
}